package cn.com.xf.dao.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapExecutor;

import cn.com.xf.dao.TblCheckReportDAO;
import cn.com.xf.dao.support.XFSqlMapClientDaoSupport;
import cn.com.xf.domain.Tbempinfo;
import cn.com.xf.domain.TblCheckReport;

@Repository
public class TblCheckReportDAOImpl extends XFSqlMapClientDaoSupport implements TblCheckReportDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public TblCheckReportDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public int deleteByPrimaryKey(Long id) {
		TblCheckReport key = new TblCheckReport();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete("TBL_CHECK_REPORT.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public void insert(TblCheckReport record) {
		getSqlMapClientTemplate().insert("TBL_CHECK_REPORT.ibatorgenerated_insert", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public void insertSelective(TblCheckReport record) {
		getSqlMapClientTemplate().insert("TBL_CHECK_REPORT.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public TblCheckReport selectByPrimaryKey(Long id) {
		TblCheckReport key = new TblCheckReport();
		key.setId(id);
		TblCheckReport record = (TblCheckReport) getSqlMapClientTemplate()
				.queryForObject("TBL_CHECK_REPORT.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public int updateByPrimaryKeySelective(TblCheckReport record) {
		int rows = getSqlMapClientTemplate().update("TBL_CHECK_REPORT.ibatorgenerated_updateByPrimaryKeySelective",
				record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_CHECK_REPORT
	 * 
	 * @ibatorgenerated Sun Aug 28 10:31:40 CST 2016
	 */
	public int updateByPrimaryKey(TblCheckReport record) {
		int rows = getSqlMapClientTemplate().update("TBL_CHECK_REPORT.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	@Override
	public TblCheckReport selectByUseridAndCheckdate(String userid, Date checkdate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", userid);
		map.put("checkdate", checkdate);
		TblCheckReport record = (TblCheckReport) getSqlMapClientTemplate()
				.queryForObject("TBL_CHECK_REPORT.selectByUseridAndCheckdate", map);
		return record;
	}

	@Override
	public List<TblCheckReport> select(int begin, int pageSize, String userid, String siteid, String deptid,
			Date startdate, Date enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return getSqlMapClientTemplate().queryForList("TBL_CHECK_REPORT.select", map);
	}

	@Override
	public int selectCount(String userid, String siteid, String deptid, Date startdate, Date enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return (Integer) getSqlMapClientTemplate().queryForObject("TBL_CHECK_REPORT.selectCount", map);
	}

	@Override
	public List<TblCheckReport> selectAll(String userid, String siteid, String deptid, Date startdate, Date enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return getSqlMapClientTemplate().queryForList("TBL_CHECK_REPORT.selectAll", map);
	}

	@Override
	public int selectAllCount(String userid, String siteid, String deptid, Date startdate, Date enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return (Integer) getSqlMapClientTemplate().queryForObject("TBL_CHECK_REPORT.selectAllCount", map);
	}

	@Override
	public int insertBatch(final List<TblCheckReport> list) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				for (TblCheckReport s : list) {

					executor.insert("TBL_CHECK_REPORT.ibatorgenerated_insert", s);

				}
				executor.executeBatch();
				return null;
			}
		});

		return 0;
	}

	@Override
	public int updateBatch(final List<TblCheckReport> list) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				for (TblCheckReport s : list) {

					executor.update("TBL_CHECK_REPORT.ibatorgenerated_updateByPrimaryKey", s);

				}
				executor.executeBatch();
				return null;
			}
		});
		return 0;
	}

	@Override
	public List<TblCheckReport> selectTotalReport(int begin, int pageSize, String userid, String siteid, String deptid,
			String startdate, String enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return getSqlMapClientTemplate().queryForList("TBL_CHECK_REPORT.selectTotalReport", map);
	}

	@Override
	public int selectTotalReportCount(String userid, String siteid, String deptid, String startdate, String enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", userid);
		map.put("siteid", siteid);
		map.put("deptid", deptid);
		map.put("startdate", startdate);
		map.put("enddate", enddate);
		return (Integer) getSqlMapClientTemplate().queryForObject("TBL_CHECK_REPORT.selectTotalReportCount", map);
	}
}